package com.fengze.shop.common.config;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.net.UnknownHostException;

/**
 * 获取服务器配置信息
 */
@Slf4j
public class ServerInfo {

    public final static String FILE_SEP = System.getProperty("file.separator");

    public final static String NEXT_LINE = System.getProperty("line.separator");

    private static String hostName = null;

    private static String localIP = null;

    //    配置文件名称
    private static String systemConfigFile = null;

    private static String systemName = null;

    private static String systemRootPath = null;


    public static String getServersPath() {
        String path = null;
        java.io.File file = new java.io.File(".");
        try {
            path = file.getCanonicalPath() + FILE_SEP;
        } catch (IOException ex) {
            log.error("Get Server Path error: {}", ex.toString());
        }

        return path;
    }

    public static String getSystemRootPath() {
        if (systemRootPath == null) {
            systemRootPath = System.getProperty("catalina.base") + FILE_SEP + "conf";
        }
        return systemRootPath;
    }

    public static String getHostName() {
        try {
            hostName = java.net.InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException ex) {
            log.error("get host name error: " + ex.toString());
        }

        return hostName;
    }

    public static String getLoaclIP() {
        try {
            localIP = java.net.InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException ex) {
            log.error("get local IP error: " + ex.toString());
        }

        return localIP;
    }

    public static String getSystemName() {
        return systemName;
    }

    public static void setSystemName(String systemName) {
        ServerInfo.systemName = systemName;
    }

    public static String getSystemConfigFile() {
        return systemConfigFile;
    }

    public static void setSystemConfigFile(String systemConfigFile) {
        ServerInfo.systemConfigFile = systemConfigFile;
    }

}
